import { Injectable, CanActivate, ExecutionContext } from '@nestjs/common';
import { Observable } from 'rxjs';

@Injectable()
export class YuicGuard implements CanActivate {
  constructor(private levael: number = 0) {}
  canActivate(
    context: ExecutionContext,
  ): boolean | Promise<boolean> | Observable<boolean> {
    const request = context.switchToHttp().getRequest();
    const mylevel = request.query?.level;
    request.yuicInfo = {
      levelClass: mylevel > 99 ? 'Vip' : 'Normal',
      level: mylevel,
    };
    console.log('守卫了', request.query?.level);
    if (mylevel > this.levael) {
      return true;
    } else {
      return false;
    }
    // return this.levael;
  }
}
